
import Api from '@/services/api.js';
const app = getApp();
import { checkPhoneNumber } from '@/utils/utils.js';
export default {
  data() {
    return {
      phone: '',
      pwd: '',
    }
  },
  methods: {
    handleLogin() {
      if (!this.phone) {
        return uni.showToast({ title: '请输入手机号码', icon: 'none' });
      }
      if (!checkPhoneNumber(this.phone)) {
        return uni.showToast({ title: '手机号码格式有误', icon: 'none' });
      }
      if (!this.pwd) {
        return uni.showToast({ title: '请输入密码', icon: 'none' });
      }
      this.requestLogin();
    },
    // 登录绑定
    async requestLogin() {
      const { code, result } = await this.$request({
        url: Api.hrLogin,
        method: 'POST',
        data: {
          phone: this.phone,
          pwd: this.pwd
        }
      });
      if (code === 200) {
        uni.showToast({ title: '登录成功', icon: 'none' });
        const eventChannel = this.getOpenerEventChannel();
        eventChannel.emit('refresh', { operate: 'hrLogin' })
        setTimeout(() => {
          uni.navigateBack();
        }, 500)
      }
    },
    handleCancel() {
      uni.navigateBack();
    }
  }
}